import { useState, useEffect } from 'react';
import { deleteMail } from '@/services/mail';
import { message } from 'antd';

// 删除单封邮件
const useDeleteMail = query => {
    const [loading, setLoading] = useState(false);
    const [resResult, setResult] = useState(null);

    const featchData = async () => {
        setLoading(true);
        const { code, msg } = await deleteMail(query);
        if (code === 10000) {
            setResult('ok');
        } else if (msg && msg.length > 0) {
            message.error(msg);
            setResult('fail');
        }
        setLoading(false);
    };

    useEffect(() => {
        if (query) {
            featchData();
        }
    }, [query]);

    return [loading, resResult, setResult];
};

export default useDeleteMail;
